package com.videoaggre.zcl.bean

import android.os.Parcelable
import androidx.fragment.app.Fragment
import com.flyco.tablayout.listener.CustomTabEntity
import com.squareup.moshi.JsonClass
import com.videoaggre.zcl.api.ApiCode
import com.videoaggre.zcl.common.Config
import com.videoaggre.zcl.helper.OnCheckBean
import kotlinx.android.parcel.Parcelize


/**
 * 统一数据封装类
 */
data class ResultBean<T>(var code: String = SUCCESS, var msg: String? = null, var data: T? = null) {
    //    public static final int SERVICE_ERROR = 4011;//appId不存在,请检查appId是否填写正确
    //    public static final int SERVICE_ERROR = 4012;//authCode参数错误
    //    public static final int SERVICE_ERROR = 4031;//必要参数未上传
    companion object {
        const val SUCCESS = "01"
        const val NOT_LOGIN = "17" //未登录或登录失效
        const val SERVICE_ERROR = 500 //服务器内部错误
    }

    val isOk: Boolean
        get() = code == SUCCESS
}

data class ApiData(
    var apiCode: ApiCode = ApiCode.START,
    var data: Any? = null,
    var apiName: String? = null,
    var throwable: Throwable? = null
)

data class TabEntity(
    var title: String? = "",
    var selectedIcon: Int = 0,
    var unSelectedIcon: Int = 0,
    var tag: String? = null,
    var extend: String? = null
) : CustomTabEntity {
    override fun getTabUnselectedIcon() = unSelectedIcon
    override fun getTabSelectedIcon() = selectedIcon
    override fun getTabTitle() = title

}

data class UserInfoBean(
    val token: String = ""
)

data class ImageUploadBean(
    var resId: Int = 0,
    var url: String? = null,
    var originalFile: String = "",
    var md5: String? = null,
    var filePath: String? = null,
    var uploadFileName: String? = null,
    var position: Int = 0
)

data class UploadDataBean(
    val originalFile: String = "",
    var compressFile: String = ""
)

data class AgefansHome(
    var timeTables: ArrayList<NewAnime> = ArrayList(),
    var lastUpdatedMoreLink: String = "",
    val lastUpdateds: MutableList<AgefansItem> = mutableListOf(),
    var todayRecommendedMoreLink: String = "",
    val todayRecommendeds: MutableList<AgefansItem> = mutableListOf(),
)

@Parcelize
data class NewAnime(
    val id: String = "0",
    val isnew: Boolean = false,
    val mtime: String = "",
    val name: String = "",
    val namefornew: String = "",
    val wd: Int = 0,
) : Parcelable

data class AgefansItem(
    val name: String = "",
    val link: String = "",
    val cover: String = "",
    val title: String = "",
    val tags: MutableList<AgefansDetailsTag> = mutableListOf(),
)

data class AgefansDetails(
    var name: String = "",
    var cover: String = "",
    var intro: String = "",
    val relatesSeries: MutableList<AgefansItem> = mutableListOf(),
    val recommends: MutableList<AgefansItem> = mutableListOf(),
    val tags: MutableList<AgefansDetailsTag> = mutableListOf(),
    val series: MutableList<MutableList<AgefansDetailsSerie>> = mutableListOf()
)

data class AgefansDetailsTag(
    var tagName: String = "",
    var tagValue: String = "",
)

data class AgefansDetailsSerie(
    var name: String = "",
    var link: String = "",
    var check: Boolean = false,
) : OnCheckBean {
    override fun showName() = name
    override fun check() = check
    override fun changeCheck(check: Boolean) {
        this.check = check
    }
}

data class AgefansPage<T>(
    var totalCount: Int = 0,
    var totalPage: Int = 0,
    var currentPage: Int = 1,
    var data: MutableList<T> = mutableListOf(),
)

data class AgefansCatalogType(
    var queryKey: String = "",
    var name: String = "",
    var values: MutableList<AgefansCatalogTypeValue> = mutableListOf(),
) {
    fun getCheck(): String {
        var mAgefansCatalogTypeValue = values[0]
        values.forEach {
            if (it.check) {
                mAgefansCatalogTypeValue = it
                return@forEach
            }
        }
        return mAgefansCatalogTypeValue.alias.ifEmpty { mAgefansCatalogTypeValue.typeName }
    }
}

data class AgefansCatalogTypeValue(
    var typeName: String = "",
    var alias: String = "",
    var check: Boolean = false,
) : OnCheckBean {
    override fun showName() = typeName
    override fun check() = check
    override fun changeCheck(check: Boolean) {
        this.check = check
    }
}

data class AgefansRank(
    val index: Int = 1,
    val link: String = "",
    val name: String = "",
    val rankValue: String = "",
)

@Parcelize
data class EnterdeskImage(
    val url: String,
    val width: Int,
    val height: Int,
    val detailId: String = "",
) : Parcelable

@Parcelize
data class EnterdeskClassify(
    val img: String = "",
    val name: String = "",
    var path: String = "",
    val resId: Int = 0,
    var check: Boolean = false,
) : Parcelable, OnCheckBean {
    override fun showName() = name
    override fun check() = check
    override fun changeCheck(check: Boolean) {
        this.check = check
    }
}

//data class QimanComicBrowse(
//    var nextId: String = "",
//    var qimanComicPre: MutableList<QimanComicPre> = mutableListOf(),
//)

data class QimanComicPre(
    val imageUrl: String = "",
)

data class WallpaperItem(
    val name: String,
    val container: Fragment,
)

data class MeizuoImage(
    val url: String = "",
    val currentPage: Int = 1,
    val totalPage: Int = 1,
)

data class QimanHome(
    val banner: MutableList<QimanBanner> = mutableListOf(),
    val item: MutableList<QimanItem> = mutableListOf(),
)

open class QimanItem {
    open fun spanSize() = 1
}

data class QimanBanner(
    val id: String,
    val img: String,
)

data class QimanComicHomeTitle(
    val redId: Int,
    val title: String,
    val id: Int,
) : QimanItem() {
    override fun spanSize() = Config.QIMAN_HOME_SPAN_SIZE
}

data class QimanComicHomeHot(
    val img: String,
    val name: String,
    val desc: String,
) : QimanItem() {
    override fun spanSize() = Config.QIMAN_HOME_SPAN_SIZE
}

data class QimanComicHomeNormal(
    val id: String = "",
    val img: String = "",
    val name: String = "",
    val desc: String = "",
) : QimanItem()

data class QimanComicChapter(
    val id: String,
    val name: String,
)